package handler

import (
	"bytes"
	"github.com/BSNDA/PCNGateway-Go-SDK/errno"
	"github.com/BSNDA/PCNGateway-Go-SDK/model"
	"github.com/gin-gonic/gin"
	"io"
	"io/ioutil"
	"log"
	"fmt"
)

func SetNFT(c *gin.Context){
	buf := &bytes.Buffer{}
	tea := io.TeeReader(c.Request.Body, buf)
	body, err := ioutil.ReadAll(tea)
	if err!=nil{
		log.Fatal(err.Error())}
	data:=string(body)
	fmt.Println(body)
	//上链函数
	message,err:=model.SetNFT(data)
	if err != nil {
		SendResponse(c, errno.ErrDatabase, nil)
		return
	}
	SendResponse(c, nil, message)

}

func GetNFT(c *gin.Context){
	buf := &bytes.Buffer{}
	tea := io.TeeReader(c.Request.Body, buf)
	body, err := ioutil.ReadAll(tea)
	if err!=nil{
		log.Fatal(err.Error())}
	data:=string(body)
	message,err:=model.GetNFT(data)
	if err != nil {
		SendResponse(c, errno.ErrDatabase, nil)
		return
	}
	fmt.Println(message)
	SendResponse(c, nil, message)

}